package com.fxcomponents.mp3player
{
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;

	public class TimerTF extends TextField
	{
		public function TimerTF()
		{
			super();
			
			autoSize = TextFieldAutoSize.LEFT;
			selectable = false;
		}
		
		// Modes
		
		public static const ELAPSED:uint = 0;
		public static const ELAPSED_TOTAL:uint = 1;
		public static const NONE:uint = 2;
		
		// Setters
		
		private var _mode:uint = ELAPSED;
		
		public function set mode(value:uint):void
		{
			_mode = value;
			
			if(_mode == NONE)
				visible = false;
			else
				visible = true;
		}
		
		private var _total:uint;
		
		public function set total(value:uint):void
		{
			_total = value;
			
			output();
		}
		
		private var _time:uint;
		
		public function set time(value:uint):void
		{
			_time = value;
			
			output();		
		}
		
		// Private Functions
		
		private function output():void
		{
			if(_mode == ELAPSED_TOTAL)
				text = formatTime(_time) + " / " + formatTime(_total);
				
			if(_mode == ELAPSED)
				text = formatTime(_time);
		}
		
		private function formatTime(value:int):String
		{
			var result:String = (value%60).toString();
	        if (result.length == 1)
	            result = Math.floor(value/60).toString() + ":0" + result;
	        else 
	            result = Math.floor(value/60).toString() + ":" + result;
	        return result;
		}
	}
}